/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package BackingBean;

import BO.Iter.LevelBO;
import BO.Iter.MonHocBO;
import TableModel.Level;
import TableModel.Monhoc;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import java.util.List;
import javax.faces.context.FacesContext;
import javax.faces.event.ValueChangeEvent;
import javax.faces.model.SelectItem;
import javax.servlet.http.HttpServletRequest;

/**
 *
 * @author vt
 */
public class BeforeSoanDe
{
    public static final String TAG = "TAG at Dethi Controller ";
    private String ncauhoi; 
    private Date ngaytao = new Date();
    private String maMH;
    private MonHocBO mhBO;
    private LevelBO lveBO;
    private String maLevel;

    public LevelBO getLveBO() {
        return lveBO;
    }

    public void setLveBO(LevelBO lveBO) {
        this.lveBO = lveBO;
    }

    public String getMaLevel() {
        return maLevel;
    }

    public void setMaLevel(String maLevel) {
        this.maLevel = maLevel;
    }
    public  SelectItem[] socauhoi ={ 
                      new SelectItem("2","2"),
                      new SelectItem("3","3"),
                      new SelectItem("4","4"),
                      new SelectItem("5","5")};

    public void setSocauhoi(SelectItem[] socauhoi) {
        this.socauhoi = socauhoi;
    }
    public SelectItem[] getSocauhoi() {
        return socauhoi;
    }
   public String getNcauhoi() {
        return ncauhoi;
    }

    public void setNcauhoi(String ncauhoi) {
        this.ncauhoi = ncauhoi;
    }  
  public String getMaMH() {
        return maMH;
    }
    public void setMaMH(String maMH) {
        this.maMH = maMH;
    }
    public MonHocBO getMhBO() {
        return mhBO;
    }
    public void setMhBO(MonHocBO mhBO) {
        this.mhBO = mhBO;
    
    }
  public String getTenMH(String mamh){
      Monhoc d = mhBO.findById(mamh);
      return d.getTenmh();
  }
  public Date getNgaytao() {
        return ngaytao;
    }

    public void setNgaytao(Date ngaytao) {
        this.ngaytao = ngaytao;
    }
  public String actionGo(){   
     HttpServletRequest req = (HttpServletRequest)FacesContext.getCurrentInstance().getExternalContext().getRequest();
     req.setAttribute("id_monhoc", this.maMH);
     req.setAttribute("ngaytao", convertTime(ngaytao));
     req.setAttribute("number_cauhoi",this.ncauhoi);
     req.setAttribute("id_level", this.maLevel);
      return "dtadd";
  }
  public void updateListCauHoi(ValueChangeEvent value){
      System.out.println("Giá trị So Cau Hoi truoc khi CHANGE  : " + this.ncauhoi);
        this.ncauhoi = (String) value.getNewValue();
       
  }
   public Collection getAllMonHoc(){
      ArrayList arr = new ArrayList();
      List<Monhoc> list = mhBO.listAllMonHoc();
      for(Monhoc item : list){
           SelectItem a = new SelectItem(item.getMamh(),item.getTenmh().toString(), item.getGhiChu());
           arr.add(a);
      }
      return arr;
    }
    public Collection getAllLevel(){
      ArrayList arr = new ArrayList();
      List<Level> list = lveBO.getAllLevel();
      for(Level item : list){
           SelectItem a = new SelectItem(item.getMaLevel(),item.getTenLevel());
           arr.add(a);
      }
      return arr;
    }
   public String convertTime(Date date){
       return new SimpleDateFormat("dd/MM/yyyy").format(date);
   }
}
